/*******************************************************************************
StrEnum.h

	Author:		LiuDingXi
	e-mail:		liudingxi@gmail.com
	Date time:	2007-05-10

	Copyright (C) 2000-2007
	All rights reserved.
	
*******************************************************************************/

#ifndef _STRENUM_H_
#define _STRENUM_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "typedef.h"
#include "FileMap.h"

typedef BOOL (CALLBACK* ENUMSTRPROC)(LPCTSTR, LPCTSTR, LPVOID);

class CStrEnum : public CFileMap
{
public:
	CStrEnum();
	virtual ~CStrEnum();
	

public:
	BOOL	Open(LPCTSTR szFileName, LPCTSTR szSegment);
	BOOL	Close();

	UINT	Retrieve(LPTSTR pString, UINT nMaxSize);
	LPCTSTR	GetString(UINT* pnSize);
	
	BOOL	IsEndOfFile()const;
	BOOL	Reset();

	static BOOL	Enum(LPCTSTR szFileName, ENUMSTRPROC StringProc, LPVOID lpData, LPCTSTR pSeg);
	
protected:
	LPCTSTR		m_pSegment;
	LPCTSTR		m_pSegEnd;
	UINT		m_nSegLen;

	LSIZE		m_lFileSize;
	LSIZE		m_lSeekSize;

	SSIZE		m_nMapSize;
	LOFFSET		m_lOffset;
	LPBYTE		m_pBuffer;
	
	LPCTSTR		m_pStr;
	LPCTSTR		m_pEnd;
};



/////////////////////////////////////////////////////////////////////////////
#if (_OS_ == _OS_WINCE_)

#pragma comment(lib, "StrEnum.lib")

#elif (_OS_ == _OS_WINNT_)

#ifndef _BUILD_StrEnum_LIB_

#ifdef _DEBUG

#if defined(_DLL)
#pragma comment(lib, "StrEnum_MTDLLd.lib")
#else
#if defined(_MT)
#pragma comment(lib, "StrEnum_MTd.lib")
#else
#pragma comment(lib, "StrEnum_d.lib")
#endif
#endif

#else // RELEASE

#if defined(_DLL)
#pragma comment(lib, "StrEnum_MTDLL.lib")
#else
#if defined(_MT)
#pragma comment(lib, "StrEnum_MT.lib")
#else
#pragma comment(lib, "StrEnum.lib")
#endif
#endif

#endif // NDEBUG

#endif //_BUILD_StrEnum_LIB_

#endif //(_OS_ == _OS_WINNT_)

/////////////////////////////////////////////////////////////////////////////


#endif//_STRENUM_H_
